package com.kotlin.flong.flow

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.take
import kotlinx.coroutines.runBlocking


/**
 * @Author:liangjl
 * @Date: 2020/7/10-21:43
 * @Eamil:jilongliang@sina.com
 * @Description:
 * 1、take限定大小的中间操作
 * 2、actual 在不同模块.比如：代码在公共模块里面
 */
fun myNumbers(): Flow<Int> = flow {
    try {
        emit(1)
        emit(2)
        println("hello world")
        emit(3)
    } catch (e: Exception) {
        println(e)
    } finally {
        println("finally")
    }
}

fun main() = runBlocking {
    myNumbers().take(2).collect { println(it) }
}